<?php

/**
 *   OPENSHOP 商品管理程序
 * 
 *   @link        http://baison.com.cn
 *   @copyright   Baison, Inc.
 *   @package     OpenShop
 *   @version     $Id: promise_delivery.php,v 1.0 $
 *   @author      baison <bs>
 */

define('IN_OS', true);

require(dirname(__FILE__) . '/includes/init.php');
require_once(ROOT_PATH . '/admin/includes/lib_goods.php');

$exc = new exchange($os->table("promise_delivery"), $db, 'id', 'recommend_type');

/*------------------------------------------------------ */
//-- 设置不同推荐商品的默认承诺发货天数
/*------------------------------------------------------ */

if($_REQUEST['act'] == 'edit_shipping_days') {
	$id = intval($_POST['id']);
    $shipping_days = json_str_iconv(trim($_POST['val']));
    if ($exc->edit("shipping_days = '$shipping_days'", $id)) {
        clear_cache_files();
        make_json_result(stripslashes($shipping_days));
    }
} else {
	$smarty->assign('ur_here', '设置承诺发货天数');
	$smarty->assign('action_link', array('href' => 'goods.php?act=list', 'text' => '商品列表'));
	$smarty->assign('full_page', 1);
	$smarty->assign('promise_delivery_list', get_promise_delivery_list());
	$smarty->display('promise_delivery.tpl');
}

function get_promise_delivery_list() {
	$recommend_type_array = get_recommend_type_array();
	$rows = $GLOBALS['db']->getAll("SELECT * FROM " . $GLOBALS['os']->table('promise_delivery'));
	foreach($rows as $key => $val) {
		$rows[$key]['formated_recommend_type'] = $recommend_type_array[$val['recommend_type']];
	}
	return $rows;
}

function get_recommend_type_array() {
	return array('is_general' => '普通', 'is_best' => '精品', 'is_new' => '新品', 'is_hot' => '热销', 'is_presale' => '预售');
}

?>